package com.wl2o2o.lanqiao.xzfourteen;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;

public class CLZ银行问题 {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        Queue<String> vipQueue = new LinkedList<>();//VIP queue
        Queue<String> normalQueue = new LinkedList<>();//normal queue
        int m = Integer.parseInt(in.readLine());
        for (int i = 0; i < m; i++) {
            String[] s = in.readLine().split(" ");
            if (s[0].equals("IN")) {
                if (s[2].equals("V")) {
                    vipQueue.offer(s[1]);
                } else {
                    normalQueue.offer(s[1]);
                }
            } else {
                if (s[1].equals("V")) {
                    if (!vipQueue.isEmpty()) {
                        vipQueue.poll();
                    }
                } else {
                    if (!normalQueue.isEmpty()) {
                        normalQueue.poll();
                    }
                }
            }
        }
        // output VIP queue
        int v = vipQueue.size();
        for (int i = 0; i < v; i++) {
            out.print(vipQueue.peek() + " ");
            vipQueue.offer(vipQueue.poll());
        }
        out.println();
        // output normal queue
        int n = normalQueue.size();
        for (int i = 0; i < n; i++) {
            out.print(normalQueue.peek() + " ");
            normalQueue.offer(normalQueue.poll());
        }
        out.flush();
    }
}